home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Tools for Macintosh
/
Power Tools for Macintosh (SoftBit)(1992).iso
/
Applications
/
Alpha 4.01
/
ACMDS
/
UnComment Box.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-01
|
3KB
|
124 lines
/****************************************************************
* *
* When debugging, set the project type to application, *
* and add the ANSI project. *
* *
* When all your bugs are out, 'undef' DEBUG, set the project *
* type to Code Resource, with type = ACMD, name = <the name *
* of the function>, file type to 'AEXT', and the purgeable *
* flag set to true. *
* *
* Also, you need to remove the ANSI project from the ACMD *
* project and replace it with the ANSI-A4 project if you use *
* any functions in ANSI, such as strlen. *
* *
* If you are not using THINK C, I'm not quite sure what you *
* should do. :-) *
* *
****************************************************************/
#undef DEBUG
#include <stdio.h>
#include <string.h>
#define STAR '*'
#define CR '\r'
/**************************************************************
* *
* This has to be called w/ exactly the right selection, *
* namely the text from the beginning of the first comment *
* line to the beginning of the line after the last comment *
* line. *
* *
**************************************************************/
char *
#ifdef DEBUG
dummy(inStr)
#else DEBUG
main(inStr)
#endif DEBUG
char *inStr;
{
char *ptr = inStr, *tptr;
size_t sz;
sz = GetPtrSize(inStr);
while (*ptr)
{
if (*ptr == '/')
{
tptr = ptr;
while (*tptr++ != CR); /* step past the star line */
while (*tptr++ != CR); /* step past the blank line */
memmove(ptr, tptr, sz - (tptr - inStr));
}
else
{
/* must be either interior line or last line */
if (*(ptr + 1) == ' ')
{
/* interior line */
memmove(ptr, ptr + 2, sz - ((ptr + 2) - inStr));
while (*ptr++ != CR);
ptr -= 3;
memmove(ptr, ptr + 2, sz - ((ptr + 2) - inStr));
ptr++;
}
else
{
/* last line, so go back and remove the blank line */
ptr--;
while (*--ptr != CR);
ptr++;
*ptr = 0;
}
}
}
return(inStr);
}
#ifdef DEBUG
char * ConvertRtoN(char *theStr);
char * ConvertRtoN(theStr)
char *theStr;
{
char *currentChar;
for (currentChar = theStr;*currentChar != 0; currentChar++)
if (*currentChar == '\r')
*currentChar = '\n';
}
main()
{
char *str = "/*********\r* this *\r* is and *\r*********/\r";
char *ret, *in;
in = NewPtr(strlen(str) + 1);
strcpy(in, str);
ret = dummy(in);
ConvertRtoN(ret); /* Convert '\r' to '\n' so we can see them in a printf */
ConvertRtoN(str);
printf("The original is:\n\n%s", str);
printf("\n----\n\nThe result is:\n\n%s", ret);
}
#endif DEBUG